home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 February
/
EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso
/
enigma
/
earcd
/
utility
/
utilfile
/
xpksourc.lha
/
xpk_Source
/
examples
/
xsum.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-10-19
|
2KB
|
62 lines
/* XSum.c - sums up all bytes in a compressed or uncompressed file
*
* This is a typical read-and-process xpk application. Try it out... XSum a
* file, then compress it and XSum it again. The result should be the same.
*/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/xpk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Library *XpkBase = NULL;
char errbuf[XPKERRMSGSIZE + 1], *outbuf = NULL;
long outlen, outbuflen;
void
end (char *text)
{
if (outbuf)
FreeMem (outbuf, outbuflen);
if (text)
Write (Output (), text, strlen (text));
if (XpkBase)
CloseLibrary (XpkBase);
exit (text ? 10 : 0);
}
void
main (int argc, char *argv[])
{
UBYTE *ptr, *last;
ULONG sum = 0;
if (!(XpkBase = OpenLibrary (XPKNAME, 0)))
end ("Cannot open " XPKNAME "\n");
if (argc != 2)
end ("Usage: XChecksum filename\n");
if (XpkUnpackTags (
XPK_InName, argv[1], /* The file name to be read */
XPK_GetError, errbuf, /* A pointer to the error message buffer */
XPK_GetOutBuf, &outbuf, /* Sets a pointer to the output buffer */
XPK_GetOutLen, &outlen, /* Sets the number of bytes written */
XPK_GetOutBufLen, &outbuflen, /* Sets the length of the output buffer */
XPK_PassThru, TRUE, /* Will pass through uncompressed data */
TAG_DONE
))
end (strcat (errbuf, "\n"));
ptr = (UBYTE *) outbuf;
last = ptr + outlen;
while (ptr < last)
sum += *ptr++;
printf ("%d\n", sum);
end (NULL);
}